<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Controllers;

use App\Admin\Repositories\VoucherPackage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class VoucherPackageController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new VoucherPackage('user'), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableRefreshButton();
            $grid->disableActions();
            $grid->disableViewButton();
            $grid->disableRowSelector();
            $grid->column('id')->sortable();
            $grid->column('user.name', '用户名');
            $grid->column('user.flag', '用户标签');
            $grid->column('user.telephone', '会员电话')->copyable();
            $grid->column('total_number');
            $grid->column('current_quantity');
            $grid->column('usage_quantity');
//            $grid->column('type');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new VoucherPackage(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('total_number');
            $show->field('current_quantity');
            $show->field('usage_quantity');
//            $show->field('type');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new VoucherPackage(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('total_number');
            $form->text('current_quantity');
            $form->text('usage_quantity');
//            $form->text('type');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
